<template>
  <a-form
    ref="formRef"
    :model="formState"
    name="basic"
    :label-col="{ span: 6 }"
    :wrapper-col="{ span: 14 }"
    autocomplete="off"
    @finish="onFinished"
    @finishFailed="onFinishFailed"
  >
    <a-form-item label="项目" name="project" :rules="[{ required: true, message: '请输入' }]">
      <a-select ref="select" placeholder="请选择" v-model:value="formState.project">
        <a-select-option value="a">项目a</a-select-option>
        <a-select-option value="b">项目b</a-select-option>
        <a-select-option value="c">项目c</a-select-option>
        <a-select-option value="d">项目d</a-select-option>
      </a-select>
    </a-form-item>

    <a-form-item label="采集器" name="hub" :rules="[{ required: true, message: '请输入' }]">
      <a-select ref="select" placeholder="请选择" v-model:value="formState.hub">
        <a-select-option value="a">采集器a</a-select-option>
        <a-select-option value="b">采集器b</a-select-option>
        <a-select-option value="c">采集器c</a-select-option>
      </a-select>
    </a-form-item>

    <a-form-item label="传感器" name="sensor" :rules="[{ required: true, message: '请输入' }]">
      <a-select ref="select" placeholder="请选择" v-model:value="formState.sensor">
        <a-select-option value="a">传感器a</a-select-option>
        <a-select-option value="b">传感器b</a-select-option>
        <a-select-option value="c">传感器c</a-select-option>
      </a-select>
    </a-form-item>

    <a-form-item label="采集器参数" name="params" :rules="[{ required: true, message: '请输入' }]">
      <a-select ref="select" placeholder="请选择" v-model:value="formState.params">
        <a-select-option value="a">采集器参数a</a-select-option>
        <a-select-option value="b">采集器参数b</a-select-option>
        <a-select-option value="c">采集器参数c</a-select-option>
      </a-select>
    </a-form-item>

    <a-form-item label="预警上限" name="limit1">
      <a-input v-model:value="formState.limit1" />
    </a-form-item>

    <a-form-item label="预警下限" name="limit2">
      <a-input v-model:value="formState.limit2" />
    </a-form-item>

    <a-form-item :wrapper-col="{ offset: 6, span: 16 }">
      <a-button type="primary" html-type="submit">确定</a-button>
    </a-form-item>
  </a-form>
</template>
  <script lang="ts">
import { defineComponent, ref } from 'vue';

interface FormState {
  project: string;
  hub: string;
  sensor: string;
  remark: string;
  params: string;
  limit1: string;
  limit2: string;
}
export default defineComponent({
  setup(props, { emit }) {
    const formRef = ref();

    const plainOptions = ['项目集成', '设备管理', '预警管理', '健康分析', '报表管理', '系统管理'];

    let formState = ref<FormState>({
      project: '',
      hub: '',
      sensor: '',
      remark: '',
      params: '',
      limit1: '',
      limit2: '',
    });

    const onFinishFailed = (errorInfo: any) => {
      console.log('Failed:', errorInfo);
    };

    const setForm = (formData) => {
      if (formData) {
        formState.value = { ...formData };
      } else {
        formRef.value.resetFields();
      }
    };

    const onFinished = (event) => {
      emit('finished', { ...event });
    };

    return {
      formState,
      onFinishFailed,
      setForm,
      formRef,
      onFinished,
      plainOptions,
    };
  },
});
</script>
  
  